/**
    * 思路1: 转化为异或运算
    */
public int hammingDistance(int x, int y) {
    x = x ^ y;
    int ans = 0;
    while (x > 0) {
        ans += (x & 1);
        x = x >> 1;
    }
    return ans;
}

class Solution {
    /**
     * 思路2:
     *      若: x(10001000)
     *      且: x(10000111)
     * 则x&(x-1) (10000000)
     *
     * 结论: x&(x-1) 为x删去最后一位1的值
     *
     */
    public int hammingDistance(int x, int y) {
        x = x ^ y;
        int ans = 0;
        while (x > 0) {
            x = x & (x - 1);
            ans++;
        }
        return ans;
    }
}
